package com.tool.creatBean;


import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import org.beetl.core.resource.StringTemplateResourceLoader;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class TestBeetl {
    public static void main(String[] args) throws IOException {
        List<TableInfo> list = new ArrayList<>();
        TableInfo tableInfo = new TableInfo();
        tableInfo.setId("did");
        tableInfo.setTablename("device");
        list.add(tableInfo);

        //初始化代码
        StringTemplateResourceLoader resourceLoader = new StringTemplateResourceLoader();
        Configuration cfg = Configuration.defaultConfiguration();
        GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);

        //获取模板
        String tt="hello,${table.tablename}";
        String tt2="<%" +
                "for(t in data){ " +
                "println(t.tablename);" +
                "}" +
                "%>";
        String tt3=
                "@for(item in data){\n" +
                "<li>${item.tablename}</li>" +
                "@}\n" ;
        String tt4="@ var a=55;" +
                "";
        Template t = gt.getTemplate(tt3);
        t.binding("table", tableInfo);
        t.binding("data",list);
        //渲染结果
        String str = t.render();
        System.out.println(str);
    }

}
